import os

env = Environment(
    ENV = os.environ,
    CXXFLAGS= ['-g', '-Wall', '-Wextra',
               '-pedantic', '-std=c++17',
               '-I/usr/local/include', '-I.'],
    CPPPATH='..',
    LINKFLAGS=['-L/usr/local/lib'])

# allows highighting to print to terminal from compiler output
env['ENV']['TERM'] = os.environ['TERM']

try:
    env.Replace(CXX=os.environ['CXX'])
except KeyError:
    pass

if env['CXX'].startswith('clang++'):
    env['CXXFLAGS'].append('-stdlib=libc++')
    env['LINKFLAGS'].append('-stdlib=libc++')

progs = Split(
    '''
    accumulate
    batched
    chain
    chunked
    combinations
    combinations_with_replacement
    compress
    count
    cycle
    dropwhile
    enumerate
    filter
    filterfalse
    groupby
    imap
    permutations
    powerset
    product
    range
    repeat
    reversed
    slice
    sliding_window
    starmap
    sorted
    takewhile
    unique_everseen
    unique_justseen
    zip

    iteratoriterator
    iterator_wrapper
    iterbase
    mixed
    helpers
    '''
)

conf = Configure(env)

# if catch isn't available, exit
if not conf.CheckCXXHeader('catch.hpp'):
    print("WARNING: catch.hpp not found, run ./download_catch.sh first")
    print("note: you may receive this warning if the c++ compiler specified "
          "by CXX  at the top of the SConstruct file is invalid.")
    Exit(1)

if conf.CheckCXXHeader('boost/optional.hpp'):
    progs.append('zip_longest')

env = conf.Finish()

test_sources = ['test_{}.cpp'.format(p) for p in progs]

for test_src in test_sources:
    env.Program([test_src, 'test_main.cpp'])

env.Program('test_all', ['test_main.cpp'] + test_sources)
